package tankattack.sprites;

import gamepack.*;
import java.util.Vector;
import java.awt.*;
import java.awt.image.*;

/** @author Somanath
*/

// 'type' Attribute may be -
interface BrickType { public int STRONG=0,WEAK=1,WATER=2,FOREST=3,BASE=4; }

/**  CompileTime class Dependency - None
 *   Runtime class Dependency     - None
 *   RunTime interface Requirements - None
*/
public class Brick extends Sprite implements BrickType {

    public static Resource r = ResourceLoader.getResource("tankattack.sprites.Brick");

    static {
		//System.out.println("#########################  Brick.java Compiled ##########################");
        // STRONG,WEAK,BASE are marked with this attribute as Bullets
        // can collide with them. WATER,FOREST are not as Bullets don't see them
        //Environment.createAttribute("COLLIDABLE_BRICK");
	}

	//--------------------------------------------------------------------
	// All bricks are of same size.
	public static int width = r.img[0][0].img.getWidth(null);
	public static int height = r.img[0][0].img.getHeight(null);

    public boolean hurt(int damage) {
           //if( type != Brick.STRONG ) {
		    if ( true ) {
              health = health - damage;
              if( health <= 0 ) {
                   setState( DYING );
              }
              return true;
           } else {
               return false;
           }
    }
	public static boolean firstWeakBrick = true;
	//--------------------------------------------------------------------
	// <Data name="spawnformat"> x=%d:0,y=%d:0,type=%d:0:(0-STRONG,1-WEAK,2-WATER,3-FOREST,4-BASE) </Data>
	public Brick()  { //Mandatory - x,y,type
		res = r;
		if( type == WATER ) { 
			setZOrder(-10);	setAttribute("BLOCK");		
		} 
		else if ( type == WEAK || type == STRONG || type == BASE ) {  
			setAttribute("BLOCK","HURTABLE"); 
			if( type == STRONG ) { health = 1000; } 
			if ( firstWeakBrick ) {
				r.img[STRONG][0] = r.img[WEAK][0];
				CImage theCImage = r.img[WEAK][0];	
				//CImage theCImage = Tank.r.img[0][2];
				
				// <Image name="player1,right"> REF (0:0 ) , rotate,180                             </Image>
				r.img[WEAK][0] = CImageUtil.affineTransform( "rotate" , theCImage , -90 );

				firstWeakBrick = false;
			}
		}
		else if ( type == FOREST ) { 
			setZOrder(10); 
		}
		startSprite();	
	}
}